

<?php
Yii::app()->clientScript->registerScript('click', "
 $('a').click(function(){
	data = $(this).attr('name');
        $('#'+data).toggle();
}
)");
Yii::app()->clientScript->registerScript('click1', "
    $('.back:radio').click(function(){
        data = $(this).attr('value');
        arr = data.split('|');
        $('#Bookings_bname').val(arr[0]);
        $('#Bookings_btime1').val(arr[1]);
        $('#Bookings_btime2').val(arr[2]);
        $('#Bookings_bcost').val(arr[3]);
        $('#Bookings_bhangVe').val(arr[4]);
        $('#Bookings_bcodeFlight').val(arr[5]);
        $('#Bookings_bcrypt').val(arr[6]);
}
)");
Yii::app()->clientScript->registerScript('click2', "
    $('.go:radio').click(function(){
        data = $(this).attr('value');
        arr = data.split('|');
        $('#Bookings_gname').val(arr[0]);
        $('#Bookings_gtime1').val(arr[1]);
        $('#Bookings_gtime2').val(arr[2]);
        $('#Bookings_gcost').val(arr[3]);
        $('#Bookings_ghangVe').val(arr[4]);
        $('#Bookings_gcodeFlight').val(arr[5]);
        $('#Bookings_gcrypt').val(arr[6]);
}
)");
$tonglon = 0;
$tongtreem=0;
$tongsosinh = 0;
$i = 1;
$j = 1;
$json = json_decode(Yii::app()->user->json, true);
$sortArray = array(); 
if (isset($json) && $json != null) {
foreach($json as $item){ 
    foreach($item as $key=>$value){ 
        if(!isset($sortArray[$key])){ 
            $sortArray[$key] = array(); 
        } 
        $sortArray[$key][] = $value; 
    } 
} }
array_multisort($sortArray['cost'],SORT_REGULAR,$json); 
?>
<div class="alert-danger thumbnail">
        <h3 class="text-danger"><strong>Lượt đi</strong></h3>
</div>
<div class="table-responsive">
<table class="table table-striped table-hover table-responsive alert-danger">
        <tr>
                
                <th>Hãng</th>
                <th>Khởi hành</th>
                <th>Đến nơi</th>
                <th>Giá</th>
                <th>Hạng vé</th>
                <th>Chuyến bay</th>
                <th>Xem chi tiết</th>
                <th>chọn</th>
        
        </tr>
        <?php
        if (isset($json) && $json != null) {

                foreach ($json as $item) {
                        if ($item['trangthai'] == 0) {
                            echo "<tr>";
                            echo "<td style='display: none;'>";
                            echo $item['name'];
                            echo "</td>";
                            echo "<td>";
                            echo  CHtml::image(Yii::app()->request->baseUrl . '/images/VN_airline.png','VN_airline' ,array('style' => 'width = 50px; height: 25px',));
                            echo "</td>";
                            echo "<td>";
                            echo $item['time1'];
                            echo "</td>";
                            echo "<td>";
                            echo $item['time2'];
                            echo "</td>";
                            echo "<td>";
                            echo $item['cost'];
                            echo "</td>";
                            echo "<td>";
                            echo $item['type_journey'];
                            echo "</td>";
                            echo "<td>";
                            echo $item['codes_flight'];
                            echo "</td>";
                            echo "<td Style='display: none;'>";
                            echo $item['crypt'];
                            echo "</td>";
                            echo "<td>";
                            echo "<a name='i".$i."'>Xem chi tiết</a>";
                            echo "</td>";
                            echo "<td>";
                            echo "<input class='go' type='radio' name='Go' value='" . $item['name'] ."|". $item['time1'] ."|". $item['time2'] ."|". $item['cost'] ."|". $item['type_journey'] ."|". $item['codes_flight'] ."|". $item['crypt'] . "' />";
                            echo "</td>";
                            echo "</tr>";
                            
                            echo "<tr id='i".$i."' Style='display: none;' >";
                            echo "<td colspan='8'>";
                       
                            echo "<table>";
                            echo "<tr><td><strong>".$item['name']."</strong></td>";
                            echo "<td><strong>Mã chuyến bay: </strong>".$item['codes_flight']."</td>";
                            echo "<td><strong>Hạng vé: </strong>". $item['type_journey'] . "</td>";
                            echo "<tr><td><strong>Bay từ: </strong>".Airports::model()->findByPk(Yii::app()->user->diemdi)->airport_name."(". Yii::app()->user->diemdi .")</td>";
                            echo "<td><strong>Bay lúc: </strong>". $item['time1'] . "</td>";
                            echo "</tr>";
                            echo "<tr><td><strong>Bay từ: </strong>".Airports::model()->findByPk(Yii::app()->user->diemden)->airport_name."(". Yii::app()->user->diemden .")</td>";
                            echo "<td><strong>Đến lúc: </strong>". $item['time2'] . "</td>";
                            echo "</tr>";
                            echo "<tr>";
                            echo "<td colspan='3' >";
                            echo "<table>";
                            echo "<tr><th>Loại vé</th><th>Số lượng</th><th>Giá</th><th>Thành tiền</th></tr>";
                            if (Yii::app()->user->nguoilon!=0) {
                                $tonglon = Yii::app()->user->nguoilon * $item['cost'];
                                echo "<tr>";
                                echo "<td>Người lớn</td>";
                                echo "<td>". Yii::app()->user->nguoilon ."</td>";
                                echo "<td>".$item['cost']."</td>";
                                echo "<td>".$tonglon."</td>";
                                echo "</tr>";
                            }
                            if (Yii::app()->user->treem!=0) {
                                $tongtreem = Yii::app()->user->treem * $item['cost'];
                                echo "<tr>";
                                echo "<td>Trẻ em</td>";
                                echo "<td>". Yii::app()->user->treem ."</td>";
                                echo "<td>".$item['cost']."</td>";
                                echo "<td>".$tongtreem."</td>";
                                echo "</tr>";
                            }
                            if (Yii::app()->user->sosinh!=0) {
                                //$tongsosinh = Yii::app()->user->sosinh *$item['cost'];
                                echo "<tr>";
                                echo "<td>Sơ sinh</td>";
                                echo "<td>". Yii::app()->user->sosinh ."</td>";
                                echo "<td>".$item['cost']."</td>";
                                echo "<td>".$tongsosinh."</td>";
                                echo "</tr>";
                            }
                            echo "</table>";
                            echo "</td>";
                            echo "</tr>"   ;                      
                            
                            
                            echo "</table>";
                            echo "<p><h4>TỔNG TIỀN:".($tonglon + $tongsosinh + $tongtreem)."</h4></p>";
                            echo "</td></tr>";
                            $i++;
                        }
                }
               
        }
        ?>
</table>
</div>
<?php if(Yii::app()->user->stt==1){ ?>
<div class="alert-danger thumbnail">
        <h3 class="text-danger"><strong>Luot ve</strong></h3>
</div>
<div class="table-responsive">
<table class="table table-striped table-hover table-responsive alert-danger">
    <tr>
        
                <th>Hãng</th>
                <th>Khởi hành</th>
                <th>Đến nơi</th>
                <th>Giá</th>
                <th>Hạng vé</th>
                <th>Chuyến bay</th>
                <th>Xem chi tiết</th>
                <th>chọn</th>
        </tr>
        <?php
         
        if (isset($json) && $json != null) {

                foreach ($json as $item) {
                        if ($item['trangthai'] == 1) {
                            echo "<tr>";
                            echo "<td style='display: none;'>";
                            echo $item['name'];
                            echo "</td>";
                            echo "<td>";
                            echo  CHtml::image(Yii::app()->request->baseUrl . '/images/VN_airline.png','VN_airline' ,array('style' => 'width = 50px; height: 25px',));
                            echo "</td>";
                            echo "<td>";
                            echo $item['time1'];
                            echo "</td>";
                            echo "<td>";
                            echo $item['time2'];
                            echo "</td>";
                            echo "<td>";
                            echo $item['cost'];
                            echo "</td>";
                            echo "<td>";
                            echo $item['type_journey'];
                            echo "</td>";
                            echo "<td>";
                            echo $item['codes_flight'];
                            echo "</td>";
                            echo "<td  Style='display: none;'>";
                            echo $item['crypt'];
                            echo "</td>";
                            echo "<td>";
                            echo "<a name='j".$j."'>Xem chi tiết</a>";
                            echo "</td>";
                            echo "<td>";
                            echo "<input type='radio' class='back' name='Back' value='" . $item['name'] ."|". $item['time1'] ."|". $item['time2'] ."|". $item['cost'] ."|". $item['type_journey'] ."|". $item['codes_flight'] ."|". $item['crypt'] . "' />";
                            echo "</td>";
                            echo "</tr>";     
                           echo "<tr id='j".$j."' Style='display: none;' >";
                            echo "<td colspan='8'>";
                       
                            echo "<table>";
                            echo "<tr><td><strong>".$item['name']."</strong></td>";
                            echo "<td><strong>Mã chuyến bay: </strong>".$item['codes_flight']."</td>";
                            echo "<td><strong>Hạng vé: </strong>". $item['type_journey'] . "</td>";
                            echo "<tr><td><strong>Bay từ: </strong>".Airports::model()->findByPk(Yii::app()->user->diemdi)->airport_name."(". Yii::app()->user->diemdi .")</td>";
                            echo "<td><strong>Bay lúc: </strong>". $item['time1'] . "</td>";
                            echo "</tr>";
                            echo "<tr><td><strong>Bay từ: </strong>".Airports::model()->findByPk(Yii::app()->user->diemden)->airport_name."(". Yii::app()->user->diemden .")</td>";
                            echo "<td><strong>Đến lúc: </strong>". $item['time2'] . "</td>";
                            echo "</tr>";
                            echo "<tr>";
                            echo "<td colspan='3' >";
                            echo "<table>";
                            echo "<tr><th>Loại vé</th><th>Số lượng</th><th>Giá</th><th>Thành tiền</th></tr>";
                           if (Yii::app()->user->nguoilon!=0) {
                                $tonglon = Yii::app()->user->nguoilon * $item['cost'];
                                echo "<tr>";
                                echo "<td>Người lớn</td>";
                                echo "<td>". Yii::app()->user->nguoilon ."</td>";
                                echo "<td>".$item['cost']."</td>";
                                echo "<td>".$tonglon."</td>";
                                echo "</tr>";
                            }
                            if (Yii::app()->user->treem!=0) {
                                $tongtreem = Yii::app()->user->treem * $item['cost'];
                                echo "<tr>";
                                echo "<td>Trẻ em</td>";
                                echo "<td>". Yii::app()->user->treem ."</td>";
                                echo "<td>".$item['cost']."</td>";
                                echo "<td>".$tongtreem."</td>";
                                echo "</tr>";
                            }
                            if (Yii::app()->user->sosinh!=0) {
                                //$tongsosinh = Yii::app()->user->sosinh *$item['cost'];
                                echo "<tr>";
                                echo "<td>Sơ sinh</td>";
                                echo "<td>". Yii::app()->user->sosinh ."</td>";
                                echo "<td>".$item['cost']."</td>";
                                echo "<td>".$tongsosinh."</td>";
                                echo "</tr>";
                            }
                            echo "</table>";
                            echo "</td>";
                            echo "</tr>"   ;                      
                            
                            
                            echo "</table>";
                            echo "<p><h4>TỔNG TIỀN:".($tonglon + $tongsosinh + $tongtreem)."</h4></p>";
                            echo "</td></tr>";
                            $j++;
                        }
                }
               
        }
        ?>
</table>
</div>
<?php }   ?>
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'bookings-form',
	'enableClientValidation'=>FALSE,
)); ?>
         <div class="row">
            <input type="hidden" value="" name="Bookings[gname]" id="Bookings_gname" />  
            <input type="hidden" value="" name="Bookings[gtime1]" id="Bookings_gtime1" />
            <input type="hidden" value="" name="Bookings[gtime2]" id="Bookings_gtime2" />
            <input type="hidden" value="" name="Bookings[gcost]" id="Bookings_gcost" />  
            <input type="hidden" value="" name="Bookings[ghangVe]" id="Bookings_ghangVe" />
            <input type="hidden" value="" name="Bookings[gcodeFlight]" id="Bookings_gcodeFlight" />
            <input type="hidden" value="" name="Bookings[gcrypt]" id="Bookings_gcrypt" />
						
            
            <input type="hidden" value="" name="Bookings[bname]" id="Bookings_bname" />   
            <input type="hidden" value="" name="Bookings[btime1]" id="Bookings_btime1" />
            <input type="hidden" value="" name="Bookings[btime2]" id="Bookings_btime2" />
            <input type="hidden" value="" name="Bookings[bcost]" id="Bookings_bcost" />  
            <input type="hidden" value="" name="Bookings[bhangVe]" id="Bookings_bhangVe" />
            <input type="hidden" value="" name="Bookings[bcodeFlight]" id="Bookings_bcodeFlight" />
            <input type="hidden" value="" name="Bookings[bcrypt]" id="Bookings_bcrypt" />
            
	</div>
        <div class="row buttons">
           
            <?php echo CHtml::submitButton('Tiếp theo');?>
           
	</div>
<?php $this->endWidget(); ?>